# Copyright 2010 Google Inc. All Rights Reserved
# Makefile for TXM
# Builds all targets in /src and /test including docs.

DOC_DIR := doc
SRC_DIR := src
INCLUDE_DIR := include
EBIN_DIR := ebin
PRIV_DIR := priv

ERL_TOP := /usr/local/lib/erlang
DIALYZER_PLT := txm.plt
PLT_DEPENDENCIES := {stdlib-*, kernel-*,mnesia-*, common_test-*, eunit-*, \
	runtime_tools-*, inets-*}

all: src test doc

.PHONY : src
src:
	$(MAKE) -C src

.PHONY: test
test:
	$(MAKE) -C test

.PHONY: doc_dir
doc_dir:
	-mkdir $(DOC_DIR)

.PHONY: doc
doc: doc_dir
	echo Building docs...
	erl -noshell -sname docs -eval \
	'edoc:application(txm, ".", [{dir, $(DOC_DIR)}, {preprocess, true}, {overview, "$(PRIV_DIR)/overview.edoc"}]).' \
	-s init stop
	echo Done.

.PHONY: run
run: src
	$(MAKE) -C src run

.PHONY: trace
trace: src
	$(MAKE) -C src trace

.PHONY: clean
clean:
	rm -rf $(DOC_DIR)
	rm -rf $(EBIN_DIR)
	rm -rf erl_crash.dump
	rm -rf *~

# The persistent lookup table is used by Dialyzer for static analysis.
# See http://www.erlang.org/doc/apps/dialyzer/dialyzer_chapter.html
# This builds the entire OTP plt from scratch which takes a LONG time.
build_otp_plt:
	dialyzer --build_plt ${ERL_TOP}/lib/$(PLT_DEPENDENCIES)/ebin
	
# This updates the plt.
plt:
	dialyzer --plt $(DIALYZER_PLT) --check_plt
	
# This runs dialyzer
dialyzer:
	dialyzer --plt $(DIALYZER_PLT) -I $(INCLUDE_DIR) $(SRC_DIR)/*.erl
